\documentclass[10pt,a4paper]{article} 

\usepackage{ctex} % 中文支持
\usepackage[top=2.5cm, bottom=2.5cm, left=2.5cm, right=2.5cm]{geometry} % 页边距
\usepackage{amsmath, amssymb} % 数学公式与符号
\usepackage{graphicx}
\usepackage{pythonhighlight}
\usepackage{url} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 插入另一个文档中的python代码
\usepackage{listings}
\usepackage{color}

% 设置列表的样式
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},   
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2
}

\lstset{style=mystyle}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{titling}
\setlength{\droptitle}{-2cm} % 标题上移

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%文档的题目、作者与日期
\author{五六七 }
\title{两种彩电的生产计划 }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\maketitle

\begin{abstract}
本文将建立模型确定两种电视机的生产规模。主要假设是价格随销量增加而下降，而且电视机的生产数量有限制条件。方法是把利润写成两种电视机的生产数量的二元函数，然后求约束条件下的最大值。
\end{abstract}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\setcounter{tocdepth}{2}
%\renewcommand\contentsname{目录}
%
%\renewcommand {\baselinestretch} {1.3}\normalsize 
%\tableofcontents 
%\renewcommand {\baselinestretch} {1.0}\normalsize


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{问题描述}
19寸电视机： 成本195元每台， 售价339元每台。 
21寸电视机： 成本225元每台， 售价399元每台。 固定成本40万元。 
每售出一台电视机， 自己价格下降1分。 
每售出一台19寸电视机， 21寸电视机降价0.4分。 
每售出一台21寸电视机， 19寸电视机降价0.3分。 
19寸电视机最多生产5000台， 21寸电视机最多生产8000台， 两种电视机总和最多10000台。 
问：各生产多少台， 可使利润最大？


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{建立模型}

本文的目标函数是一个二元函数，我们要计算其在约束条件下的最大值。我们使用的方法是用拉格朗日乘子法。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{数学表达式}
设19寸电视机每年生产$s$台，设21寸电视机每年生产$t$台。设生产出来的电视机能够全部销售。则19寸电视机的价格为每台$339-0.01s-0.003t$元，21寸电视机的价格为每台$399-0.01t-0.004s$元。总成本为$400,000+195s+225t$元。因此利润为
\begin{eqnarray}
y&=&f(s,t)\nonumber\\
&=&(339-0.01s-0.003t)s \nonumber\\
&&+(399-0.01t-0.004s)t - (400,000+195s+225t)\nonumber\\
&=& - 0.01s^2 - 0.007st + 144s - 0.01t^2 + 174t - 400000
\end{eqnarray}

%其中的约束条件为

\underline{问题A}： 写出约束条件。

%\vspace{3cm}
\underline{问题A解答}：

\begin{eqnarray}
\left\{
\begin{array}{l}
s\le 5000\\
t\le 8000\\
s+t\le 10000
\end{array}\right.
\end{eqnarray}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{可行域}
我们先来研究该带约束优化问题的可行域。由上述题目知道，两种电视机的生产规模$(s,t)$的取值范围是
\begin{eqnarray} \{(s,t)\,\,|\,\, s\le 5000, t\le 8000, s+t\le 10000,s\ge 0, t\ge 0\} . \end{eqnarray}

这个集合称为可行域。画出该区域如下。
\begin{figure}[ht!]
\centering
%\begin{center}
\includegraphics [height=5cm,width=7cm]{mmp28.eps}
\caption{约束条件的可行域}
%\end{center}
\end{figure}

下述代码画出可行域。（正式论文一般不用列出画示意图的代码）

\begin{lstlisting}[language=Matlab]
% 画出mmp28页可行域
A=[0 5000 5000 0 0];B=[0 0 8000 8000 0];line(A,B)
C=[0 10000 0 0];D=[0 0 10000 0];line(C,D)
for k=0:1000:8000
    line([0,min(5000,10000-k)],[k k])
end
axis([-1000 12000 -1000 12000])
set(gca, 'xtick',0:2000:12000)
set(gca, 'ytick',0:2000:12000)
%xlabel('s = 19寸电视机产量')
%ylabel('t = 21寸电视机产量')
%text(1500,3500,'可行域')
xlabel('s = 19-inch TV production level')
ylabel('t = 21-inch TV production level')
text(1500,3500,'Feasible set')
\end{lstlisting}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{判断最优解在可行域的内部还是边界}

先计算两个偏导数，我们知道如果函数在一个区域内部的某点取最大值，那么两个偏导数在该点的导数值都等于零。
\begin{eqnarray}
\left\{
\begin{array}{l}
\frac{dy}{ds}= - 0.02s - 0.007t + 144\\
\frac{dy}{dt}= - 0.007s - 0.02t + 174\\
\end{array}\right.
\end{eqnarray}

由$\frac{dy}{ds}=0,\frac{dy}{dt}=0$得到$s=4735,t=7042$, 这个点不在可行域中，因此在可行域内部任意一点，上述两个偏导数不会都等于零。所以函数$y=f(s,t)$ 将在边界$s=5000, 0\le t\le 5000$、或者边界$t=8000, 0\le s\le 2000$、或者边界$s+t=10000$上的某个点取到最大值。


\underline{问题B}： 函数最大值落在上图的五条边界的哪一条？

%\vspace{3cm}

考虑边界$s=5000, 0\le t\le 5000$. 这时$y=f(5000,t)=- 0.01t^2 + 139t + 70000$, $\frac{dy}{dt} = 139 - 0.02t$, 得到导数为零的点$t =6950$, 超过了$t$的最大可能取值5000. 因此函数$f(s,t)$在这条边界上的最大值在$(s,t)=(5000,5000)$取到。

同样考虑边界$t=8000, 0\le s\le 2000$. 这时$y=f(s,8000)=- 0.01s^2 + 88s + 352000$, 导数$\frac{dy}{ds} =88 - 0.02s=0$ 得到$s=4400$. 也超出了最大可能$2000$. 因此函数$f(s,t)$在这条边界上的最大值在$(s,t)=(2000,8000)$取到。


（正式论文中下述代码也不一定要加）

\begin{lstlisting}[language=Matlab]
% 判断最大值是否在两条边界上
syms s t
y=(339-0.01*s-0.003*t)*s +(399-0.004*s-0.01*t)*t -(400000+195*s+225*t)
y1=subs(y,'s','5000')
y1=simplify(y1)
dy1dt=diff(y1,t)
tcpoint=solve(dy1dt,'t')
subs(y1,'t',0), subs(y1,'t',5000), subs(y1,'t',tcpoint)

y2=subs(y,'t','8000')
y2=simplify(y2)
dy2ds=diff(y2,s)
scpoint=solve(dy2ds,'s')
subs(y2,'s',0), subs(y2,'s',5000), subs(y2,'s',scpoint)
\end{lstlisting}

下一节中我们考虑最后一种情形，即考虑从$(s,t)=(5000,5000)$到$(2000,8000)$的线段所在的边界。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{拉格朗日乘子法}
现在我们考虑如下问题
\begin{eqnarray}
\textrm{max} && f(s,t)= - 0.01s^2 - 0.007st + 144s - 0.01t^2 + 174t - 400000\nonumber \\
\textrm{suject to} && s+t= 10000
\end{eqnarray}
由拉格朗日乘子法的思路，上述约束优化问题转化为下述无约束优化问题
\begin{eqnarray}
f(s,t,\lambda)= - 0.01s^2 - 0.007st + 144s - 0.01t^2 + 174t - 400000 +\lambda(s+t-10000)
\end{eqnarray}
求偏导数并令其为零，得到
\begin{eqnarray}
\left\{
\begin{array}{l}
\frac{dy}{ds}=\lambda - 0.02s - 0.007t + 144=0\\
\frac{dy}{dt}=\lambda - 0.007s - 0.02t + 174=0\\
\frac{dy}{d\lambda} = s + t - 10000=0\\
\end{array}\right.
\Longrightarrow
\left\{
\begin{array}{l}
s=3846\\
t=6153
\end{array}\right.
\end{eqnarray}

最后代入函数，得到这个最优的生产规模下，预计获得的利润为
\begin{eqnarray}
y=f(3846,6154)=532307.69.
\end{eqnarray}


\underline{问题C}： 设函数$u=x+2y+3z$, 约束条件 $x^2+y^2+z^2=3$. 求$u$的最大值与最小值。

%\vspace{2cm}

\underline{问题D}： 设函数$u=x+2y+3z$, 约束条件 $x^2+y^2+z^2=3$与$x=1$. 求$u$的最大值与最小值。

%\vspace{2cm}

上述计算的程序如下。

\begin{lstlisting}[language=Matlab]
% 用拉格朗日乘子法求有约束条件的函数的最大值
syms s t lambda
y=(339-0.01*s-0.003*t)*s +(399-0.004*s-0.01*t)*t ...
    -(400000+195*s+225*t) +lambda*(s+t-10000)
y=simplify(y)
%%求偏导数
dyds=diff(y,s), dydt=diff(y,t)
dydlambda=diff(y,lambda)
%%解线性方程组
format bank
cpoint=solve(dyds,dydt,dydlambda,'s','t','lambda')
double(cpoint.s), double(cpoint.t)
%求函数的最大值
double(subs(y,{s,t},{3846,6154}))
\end{lstlisting}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\section{编程计算}

\section{另一种思路}
本节中我们用穷举法求出函数在约束条件下的最大值。
我们每隔100台列出所有可能的生产计划，即考虑$(s,t)=(100m,100n)$, 其中$m,n=0,1,2,\cdots,100$. 然后计算相应的函数值$y$. 对于不符合约束条件$s+t\le 10000$ 的$(s,t)$, 我们再取消相应的$y$值。然后比较得到的所有函数值，找出最大值。结果为19寸电视机生产3800台，21寸电视机生产6200台，预期所获利润为532280元。

\begin{figure}[h!]
\centering
%\begin{center}
\includegraphics [height=5cm,width=\textwidth]{mmp28surface.eps}
\caption{带约束条件的二元函数的曲面与等值线}
%\end{center}
\end{figure}

\begin{lstlisting}[language=Matlab]
% mmp28页约束优化问题，穷举法
s=0:100:5000; t=0:100:8000;
[ss,tt]=meshgrid(s,t);
yy=(339-0.01*ss-0.003*tt).*ss +(399-0.004*ss-0.01*tt).*tt ...
    -(400000+195*ss+225*tt);
yy(ss+tt>10000)=NaN;
subplot(1,2,1), surf(ss,tt,yy), %colormap(autumn)
subplot(1,2,2), contour(yy)
%xlabel('s = 19寸电视机产量')
%ylabel('t = 21寸电视机产量')
xlabel('s = 19-inch TV production level,(\times 100)')
ylabel('t = 21-inch TV production level,(\times 100)')
ymax=max(max(yy))
[n,m]=find(yy==ymax);
spoint=(m-1)*100; tpoint=(n-1)*100;
fprintf('19寸电视机生产 %4d 台，\n',spoint)
fprintf('21寸电视机生产 %4d 台，\n',tpoint)
fprintf('函数最大值为 %8.2f 元。\n',ymax)
\end{lstlisting}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{回答问题}

在上述有关价格的假设下，并考虑生产规模的约束条件，生产3846台19寸电视机，以及6154台21寸电视机，将获得最大可能的利润，最大利润预期为532307.69元。


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\section{参考文献 }
\begin{thebibliography}{99}
\bibitem{dingtongren} 丁同仁、李承治，\emph{常微分方程教程}，高等教育出版社，2022年3月第三版。
\bibitem{sishoukui-2} 司守奎,孙玺菁. \emph{Python数学建模算法与应用}, 国防工业出版社. 2022年1月第1版. 
\bibitem{meerschaert} Mark Meerschaert: \emph{数学建模方法与分析}, 机械工业出版社, 2015年。


\end{thebibliography}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


